package aerouacmsla.interfazDeUsuario;

import aerouacmsla.entidad.Boleto;
import aerouacmsla.procedimientos.BDConexion;
import java.awt.HeadlessException;
import java.awt.event.KeyEvent;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;

/**
 *
 * @author Marco
 */
public class PanelAtenderPasajeros extends javax.swing.JPanel {

    private BDConexion miConexion;
    private String nombreCliente;
    private String nombre;
    private String apellidoPaterno;
    private String apellidoMaterno;
    private String rfcCliente;
    private String idCliente;
    private String idUsuario;
    private JTabbedPane panelPadre;

    private boolean cambioHoraLista = false;
    private boolean cambioIdCombo = false;

    //[0] = pais
    //[1] = estado
    //[2] = ciudad
    //[3] = id
    private String[] origen = {"","","",""};
    private String[] destino = {"","","",""};
    private String hora;

    public PanelAtenderPasajeros() {
        initComponents();
    }
    public PanelAtenderPasajeros(BDConexion miConexion, javax.swing.JFrame padre) {
        initComponents();
        setMiConexion(miConexion);
    }

    public BDConexion getMiConexion() {
        return miConexion;
    }

    public JTabbedPane getPanelPadre() {
        return panelPadre;
    }

    public void setPanelPadre(JTabbedPane panelPadre) {
        this.panelPadre = panelPadre;
    }

    public void setMiConexion(BDConexion miConexion) {
        this.miConexion = miConexion;
    }

    public String getidUsuario() {
        return idUsuario;
    }

    public void setIdUsuario(String idUsuario) {
        this.idUsuario = idUsuario;
    }

    public String getHora() {
        return hora;
    }

    public void setHora(String hora) {
        this.hora = hora;
    }

    public String getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(String idCliente) {
        this.idCliente = idCliente;
    }

    public String getNombreCliente() {
        return nombreCliente;
    }

    public void setNombreCliente(String nombreCliente) {
        this.nombreCliente = nombreCliente;
    }

    public String getRfcCliente() {
        return rfcCliente;
    }

    public void setRfcCliente(String rfcCliente) {
        if (rfcCliente != null)
        this.rfcCliente = rfcCliente;
        else setRfcCliente("");
    }

    public String getApellidoMaterno() {
        return apellidoMaterno;
    }

    public void setApellidoMaterno(String apellidoMaterno) {
        this.apellidoMaterno = apellidoMaterno;
    }

    public String getApellidoPaterno() {
        return apellidoPaterno;
    }

    public void setApellidoPaterno(String apellidoPaterno) {
        this.apellidoPaterno = apellidoPaterno;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public boolean isCambioHoraLista() {
        return cambioHoraLista;
    }

    public void setCambioHoraLista(boolean cambioHoraLista) {
        this.cambioHoraLista = cambioHoraLista;
    }

    public boolean isCambioIdCombo() {
        return cambioIdCombo;
    }

    public void setCambioIdCombo(boolean cambioIdCombo) {
        this.cambioIdCombo = cambioIdCombo;
    }

    public boolean separarNombre(String nombreCompleto){
        String[] separado = nombreCompleto.split(" ");
        if (separado.length == 3) {
            setNombre(separado[0]);
            setApellidoPaterno(separado[1]);
            setApellidoMaterno(separado[2]);
            return true;
        }
        return false;
    }

    public void elegirNuevoRegistro(int index){
        getPanelPadre().setSelectedIndex(index);
    }

    public void setOrigen(String pais, String estado, String ciudad, String id){
        origen[0] = pais;
        origen[1] = estado;
        origen[2] = ciudad;
        origen[3] = id;
    }

    public String getOrigen(int index){
        if (index <=3){
            return origen[index];
        }
        return "Index Erroneo";
    }

    public String getDestino(int index){
        if (index <=3){
            return destino[index];
        }
        return "Index Erroneo";
    }

    public void setDestino(String pais, String estado, String ciudad, String id){
        destino[0] = pais;
        destino[1] = estado;
        destino[2] = ciudad;
        destino[3] = id;
    }

    public void reiniciarDatos(){
        setNombre("");
        setNombreCliente("");
        setIdCliente("");
        setRfcCliente("");
        setApellidoPaterno("");
        setApellidoMaterno("");
        setOrigen("", "", "","");
        setDestino("", "", "","");
        selectorBoletos.setValue(1);
        selectorBoletos.setEnabled(false);
        selectorDeFecha.setEditable(false);
        selectorDeFecha.setDate(null);
        campoPagoTotal.setText("");
        campoNombreCompletoCliente.setText("");
        campoIdCliente.setText("");
        campoRfcCliente.setText("");
        campoOrigen.setText(null);
        campoDestino.setText(null);
        comboVuelosDisponibles.setModel(new DefaultComboBoxModel());
        horasSalida.setModel(new DefaultComboBoxModel());
        campoAsientosLibres.setText("");
        campoPrecioVuelo.setText("");
    }

    public DefaultComboBoxModel llenarCombo(String[] elementos) {
        DefaultComboBoxModel comboModelo = new DefaultComboBoxModel();
        if (elementos != null) {
            for (int i = 0; i<elementos.length; i++){
                comboModelo.addElement(elementos[i]);
            }
            //comboModelo = new DefaultComboBoxModel(elementos);
            return comboModelo;
        }
        return comboModelo;
    }

    public void llenarComboVuelos(){
        if (!campoOrigen.getText().isEmpty() && !campoDestino.getText().isEmpty()){
            getMiConexion().sendSQLQuery(
                    "SELECT * FROM vuelo WHERE origen = '" + getOrigen(3) +
                    "' && destino = '" + getDestino(3) + "';"
                    );
            comboVuelosDisponibles.setModel(llenarCombo(getMiConexion().getLastResultSetColumnStrings("id_vuelo")));
        }
    }

    public void llenarListaHoras(){
        String fechaSeleccionada = selectorDeFecha.getEditor().getText();
        Calendar fecha = new GregorianCalendar();
        int annio = fecha.get(Calendar.YEAR);
        int mes = fecha.get(Calendar.MONTH) + 1;
        int dia = fecha.get(Calendar.DAY_OF_MONTH);
        
        String[] fechaSeparada = fechaSeleccionada.split("-");
        
        int annio2 = Integer.parseInt(fechaSeparada[0]);
        int mes2 = Integer.parseInt(fechaSeparada[1]);
        int dia2 = Integer.parseInt(fechaSeparada[2]);

        String busquedaHora = null;
        boolean fechaAnterior = false;

        /* Comparacion de fecha actual
         * con la fecha seleccionada
         * para ver si es una fecha anterior a la actual
         */
        if (annio2 < annio) {
            fechaAnterior = true;
        }
        else if (annio2 == annio){
            if (mes2 < mes){
                fechaAnterior = true;
            }
            else if (dia2 < dia){
                fechaAnterior = true;
            }
            else{
                fechaAnterior = false;
                String horaActual = fecha.get(Calendar.HOUR_OF_DAY) + "";
                String minutoActual = fecha.get(Calendar.MINUTE) + "";
                if (horaActual.length() < 2) horaActual = "0" + horaActual;
                if (minutoActual.length() < 2) minutoActual = "0" + minutoActual;
                busquedaHora =horaActual + ":" + minutoActual + ":00";
            }
        }
        System.out.println(fechaAnterior);
        if (!fechaAnterior) {
            if (!campoOrigen.getText().isEmpty() && !campoDestino.getText().isEmpty()){
                /*getMiConexion().sendSQLQuery(
                        "SELECT id_vuelo, hora_salida FROM vuelo WHERE origen = '" + getOrigen(3) +
                        "' && destino = '" + getDestino(3) + "' && fecha = '" + fechaSeleccionada + "' &&"
                        + " hora_salida >='" + busquedaHora + "' && asientos_disponibles > 0;"
                        );*/
                getMiConexion().sendSQLQuery(
                        "SELECT id_vuelo, hora_salida FROM vuelo WHERE origen = '" + getOrigen(3) +
                        "' && destino = '" + getDestino(3) + "' && fecha = '" + fechaSeleccionada + "'"
                        + " && asientos_disponibles > 0;"
                        );
                comboVuelosDisponibles.setModel(llenarCombo(getMiConexion().getLastResultSetColumnStrings("id_vuelo")));
                horasSalida.setModel(llenarCombo(getMiConexion().getLastResultSetColumnStrings("hora_salida")));
                if (horasSalida.getModel().getSize() > 0)
                    horasSalida.setSelectedIndex(0);
                if (comboVuelosDisponibles.getModel().getSize() > 0)
                    comboVuelosDisponibles.setSelectedIndex(0);
            }
        }
    }
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        fieldBuscarUsuario = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        buttonBuscarUsuario = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        campoIdCliente = new javax.swing.JTextField();
        campoNombreCompletoCliente = new javax.swing.JTextField();
        campoRfcCliente = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        comboVuelosDisponibles = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        campoOrigen = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        campoDestino = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        campoAsientosLibres = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        campoPrecioVuelo = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        selectorDeFecha = new org.jdesktop.swingx.JXDatePicker();
        jScrollPane1 = new javax.swing.JScrollPane();
        horasSalida = new javax.swing.JList();
        jPanel4 = new javax.swing.JPanel();
        selectorBoletos = new javax.swing.JSpinner();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        campoPagoTotal = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        PreviewBoleto = new javax.swing.JScrollPane();
        jLabel14 = new javax.swing.JLabel();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Busqueda de Pasajeros"));

        fieldBuscarUsuario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                fieldBuscarUsuarioKeyPressed(evt);
            }
        });

        jLabel1.setText("Nombre o ID");

        buttonBuscarUsuario.setText("Buscar");
        buttonBuscarUsuario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonBuscarUsuarioMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(fieldBuscarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonBuscarUsuario)
                .addContainerGap(14, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fieldBuscarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(buttonBuscarUsuario))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Pasajero"));
        jPanel2.setEnabled(false);

        jLabel2.setText("ID");

        jLabel3.setText("Nombre Completo");

        jLabel4.setText("RFC");

        campoIdCliente.setEditable(false);

        campoNombreCompletoCliente.setEditable(false);

        campoRfcCliente.setEditable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoNombreCompletoCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                    .addComponent(campoIdCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                    .addComponent(campoRfcCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(campoIdCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(campoNombreCompletoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(campoRfcCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Vuelo"));
        jPanel3.setEnabled(false);

        comboVuelosDisponibles.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboVuelosDisponiblesItemStateChanged(evt);
            }
        });

        jLabel5.setText("Disponibles");

        campoOrigen.setEditable(false);

        jLabel6.setText("Origen");

        campoDestino.setEditable(false);

        jLabel7.setText("Destino");

        jLabel8.setText("Hora salida");

        jButton2.setText("...");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jButton3.setText("...");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        jLabel11.setText("Asientos");

        campoAsientosLibres.setEditable(false);

        jLabel12.setText("Precio");

        campoPrecioVuelo.setEditable(false);

        jLabel13.setText("Fecha");

        selectorDeFecha.setEditable(false);
        selectorDeFecha.setFormats(new SimpleDateFormat("yyyy-MM-dd"));
        selectorDeFecha.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                selectorDeFechaPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        horasSalida.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        horasSalida.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                horasSalidaValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(horasSalida);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel13))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel3Layout.createSequentialGroup()
                                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(campoDestino, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(campoOrigen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(selectorDeFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboVuelosDisponibles, 0, 226, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(campoAsientosLibres)
                            .addComponent(campoPrecioVuelo, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoOrigen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoDestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(selectorDeFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboVuelosDisponibles)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(campoAsientosLibres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(campoPrecioVuelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Costos"));
        jPanel4.setEnabled(false);

        selectorBoletos.setModel(new javax.swing.SpinnerNumberModel(1, 1, 300, 1));
        selectorBoletos.setEnabled(false);
        selectorBoletos.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                selectorBoletosStateChanged(evt);
            }
        });

        jLabel9.setText("Boletos a comprar");

        jLabel10.setText("Cantidad a Pagar");

        campoPagoTotal.setEditable(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoPagoTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                    .addComponent(selectorBoletos, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE))
                .addGap(153, 153, 153))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(selectorBoletos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(campoPagoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        jButton4.setText("Pagar");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });

        jButton1.setText("Reiniciar Datos");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jLabel14.setText("Preview Boleto");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(PreviewBoleto, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                    .addComponent(jLabel14))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(PreviewBoleto, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)))
                .addGap(24, 24, 24))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void buttonBuscarUsuarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonBuscarUsuarioMouseClicked
        //busqueda del usuario si son 14 primero buscar por ID
        String informacionProporcionada = fieldBuscarUsuario.getText();
        boolean encontrado = false;
        if (informacionProporcionada.length() == 14){
            //Buscar Por ID
            getMiConexion().sendSQLQuery(
                "SELECT * FROM cliente WHERE id_cliente ='" + informacionProporcionada
                + "';");
            try {
                if (getMiConexion().getResultado().next()){
                    encontrado = true;
                    setIdCliente(getMiConexion().getResultado().getObject("id_cliente").toString());
                    setNombreCliente(
                            getMiConexion().getResultado().getObject("nombre").toString() + " " +
                            getMiConexion().getResultado().getObject("apellido_paterno").toString() + " " +
                            getMiConexion().getResultado().getObject("apellido_materno").toString() + " "
                            );
                }
            } catch (SQLException ex) {
                Logger.getLogger(PanelAtenderPasajeros.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        else if (!encontrado) {
            //Buscar por nombre
            setNombreCliente(informacionProporcionada);
            if (separarNombre(getNombreCliente())) {
                getMiConexion().sendSQLQuery(
                    "SELECT * FROM cliente WHERE " +
                    "nombre='" + getNombre()  + "' && " +
                    "apellido_paterno='" + getApellidoPaterno() + "' && " +
                    "apellido_materno='" + getApellidoMaterno() + "'; "
                    );
                try {
                    if (getMiConexion().getResultado().next()){
                        encontrado = true;
                        setIdCliente(getMiConexion().getResultado().getObject("id_cliente").toString());
                        try {
                            setRfcCliente(getMiConexion().getResultado().getObject("rfc").toString());
                        } catch (NullPointerException error) {
                            setRfcCliente("");
                        }
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(PanelAtenderPasajeros.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        if (encontrado){
            campoIdCliente.setText(getIdCliente());
            campoNombreCompletoCliente.setText(getNombreCliente());
            campoRfcCliente.setText(getRfcCliente());
        }
        else{
            int n = JOptionPane.showConfirmDialog(
                this, "El cliente no se encuentra en la base de datos, " +
                 "desea registrar al nuevo cliente?",
                 "Nuevo Cliente?",
                JOptionPane.YES_NO_OPTION);
                 if (n == 0)
                 elegirNuevoRegistro(1);
        }
    }//GEN-LAST:event_buttonBuscarUsuarioMouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        reiniciarDatos();
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        horasSalida.setModel(new DefaultComboBoxModel());
        comboVuelosDisponibles.setModel(new DefaultComboBoxModel());
        selectorDeFecha.setDate(null);
        selectorBoletos.setValue(1);
        campoPagoTotal.setText(null);
        campoAsientosLibres.setText(null);
        campoPrecioVuelo.setText(null);
        DialogoCiudades eleccionOrigen = new DialogoCiudades(getMiConexion());
        eleccionOrigen.setVisible(true);
        setOrigen(eleccionOrigen.getPais(), eleccionOrigen.getEstado(), eleccionOrigen.getCiudad(), eleccionOrigen.getId());
        campoOrigen.setText(getOrigen(2));
         if (!campoOrigen.getText().isEmpty() && !campoDestino.getText().isEmpty())
            selectorDeFecha.setEditable(true);
        //llenarComboVuelos();
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        horasSalida.setModel(new DefaultComboBoxModel());
        comboVuelosDisponibles.setModel(new DefaultComboBoxModel());
        selectorDeFecha.setDate(null);
        selectorBoletos.setValue(1);
        campoPagoTotal.setText(null);
        campoAsientosLibres.setText(null);
        campoPrecioVuelo.setText(null);
        DialogoCiudades eleccionDestino = new DialogoCiudades(getMiConexion());
        eleccionDestino.setVisible(true);
        setDestino(eleccionDestino.getPais(), eleccionDestino.getEstado(), eleccionDestino.getCiudad(), eleccionDestino.getId());
        campoDestino.setText(getDestino(2));
         if (!campoOrigen.getText().isEmpty() && !campoDestino.getText().isEmpty())
            selectorDeFecha.setEditable(true);
        //llenarComboVuelos();
    }//GEN-LAST:event_jButton3MouseClicked

    private void fieldBuscarUsuarioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldBuscarUsuarioKeyPressed
        if (KeyEvent.VK_ENTER == evt.getKeyCode()){
           buttonBuscarUsuarioMouseClicked(null);
       }
    }//GEN-LAST:event_fieldBuscarUsuarioKeyPressed

    private void selectorDeFechaPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_selectorDeFechaPopupMenuWillBecomeInvisible
        llenarListaHoras();
    }//GEN-LAST:event_selectorDeFechaPopupMenuWillBecomeInvisible

    private void comboVuelosDisponiblesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboVuelosDisponiblesItemStateChanged
        try {
            if (!cambioHoraLista) {
                int index = comboVuelosDisponibles.getSelectedIndex();
                cambioIdCombo = true;
                horasSalida.setSelectedIndex(index);
                setHora(horasSalida.getSelectedValue().toString());
                String consulta =
                        "SELECT precio, asientos_disponibles WHERE "
                        + "id_vuelo = '" + comboVuelosDisponibles.getSelectedItem().toString() + "';";
                getMiConexion().sendSQLQuery(consulta);
                try {
                    if (getMiConexion().getResultado().next()) {
                        String precio = getMiConexion().getResultado().getObject("precio").toString();
                        String asientosDisponibles = getMiConexion().getResultado().getObject("asientos_disponibles").toString();
                        campoAsientosLibres.setText(asientosDisponibles);
                        campoPrecioVuelo.setText(precio);
                        selectorBoletos.setEnabled(true);
                        selectorBoletos.setValue(1);
                        campoPagoTotal.setText(precio);
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(PanelAtenderPasajeros.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            setCambioHoraLista(false);
        } catch (Exception e) {
            //el error feo ese
        }
    }//GEN-LAST:event_comboVuelosDisponiblesItemStateChanged

    private void horasSalidaValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_horasSalidaValueChanged
        try {
            if (!isCambioIdCombo()) {
                int index = horasSalida.getSelectedIndex();
                setHora(horasSalida.getSelectedValue().toString());
                cambioHoraLista = true;
                comboVuelosDisponibles.setSelectedIndex(index);
                String consulta =
                        "SELECT precio, asientos_disponibles FROM vuelo WHERE "
                        + "id_vuelo = '" + comboVuelosDisponibles.getSelectedItem().toString() + "';";
                getMiConexion().sendSQLQuery(consulta);
                try {
                    if (getMiConexion().getResultado().next()) {
                        String precio = getMiConexion().getResultado().getObject("precio").toString();
                        String asientosDisponibles = getMiConexion().getResultado().getObject("asientos_disponibles").toString();
                        campoAsientosLibres.setText(asientosDisponibles);
                        campoPrecioVuelo.setText(precio);
                        selectorBoletos.setEnabled(true);
                        selectorBoletos.setValue(1);
                        campoPagoTotal.setText(precio);
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(PanelAtenderPasajeros.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            setCambioIdCombo(false);
        } catch (Exception e) {
            //el error feo ese
        }
    }//GEN-LAST:event_horasSalidaValueChanged

    private void selectorBoletosStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_selectorBoletosStateChanged
        try {
            int cantidadDeBoletos = Integer.parseInt(selectorBoletos.getValue().toString());
            float precioTotal = cantidadDeBoletos * Float.parseFloat(campoPrecioVuelo.getText().toString());
            campoPagoTotal.setText(precioTotal + "");
        } catch (Exception e) {
            //Cambiado desde otro lado
        }
    }//GEN-LAST:event_selectorBoletosStateChanged

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked
        //Revisamos si hay algun cliente seleccionado.
        if (!campoIdCliente.getText().isEmpty()) {
            //Revisamos si ya hay seleccionado un origen y destino
            if (!campoOrigen.getText().isEmpty() && !campoDestino.getText().isEmpty()){
                if (comboVuelosDisponibles.getSelectedIndex() != -1) {
                    try {
                        //creando un boleto
                        int asientosDisponibles = 0;
                        int asientosDelAvion = 0;
                        int idAvion = 0;
                        int boletosComprados = Integer.parseInt(selectorBoletos.getValue().toString());
                        int asientosSobrantes = 0;
                        getMiConexion().getConexion().setAutoCommit(false);
                        getMiConexion().sendSQLQuery("SELECT asientos_disponibles, id_avion "
                                + "FROM vuelo WHERE id_vuelo = '" + comboVuelosDisponibles.getSelectedItem().toString() + "';");
                        if (getMiConexion().getResultado().next()){
                            asientosDisponibles = getMiConexion().getResultado().getInt("asientos_disponibles");
                            idAvion = getMiConexion().getResultado().getInt("id_avion");
                        }
                        getMiConexion().sendSQLQuery("SELECT numero_asientos "
                                + "FROM avion WHERE id_avion = " + idAvion + ";");
                        if (getMiConexion().getResultado().next()){
                            asientosDelAvion = getMiConexion().getResultado().getInt("numero_asientos");
                        }
                        int asientosAOcupar = (asientosDelAvion - asientosDisponibles) + 1;
                        asientosSobrantes = asientosDisponibles - boletosComprados;
                        if (asientosSobrantes >= 0) {
                            Boleto miBoleto[] = new Boleto[boletosComprados];
                            PanelBoleto imprimirBoletos[] = new PanelBoleto[boletosComprados];
                            for (int i = 0; i < miBoleto.length; i++) {
                                miBoleto[i] = new Boleto();
                                imprimirBoletos[i] = new PanelBoleto();
                                imprimirBoletos[i].setIdBoleto((i + asientosAOcupar) + "");
                                imprimirBoletos[i].setOrigen(getOrigen(2));
                                imprimirBoletos[i].setDestino(getDestino(2));
                                imprimirBoletos[i].setHora(horasSalida.getSelectedValue().toString());
                                imprimirBoletos[i].setFecha(selectorDeFecha.getEditor().getText());
                                imprimirBoletos[i].setNumeroAsiento(i + asientosAOcupar + "");
                                miBoleto[i].setIdPasajero(getIdCliente());
                                miBoleto[i].setIdVuelo(comboVuelosDisponibles.getSelectedItem().toString());
                                miBoleto[i].setAsiento(i + asientosAOcupar);
                            }
                            getMiConexion().sendSQL("UPDATE vuelo SET"
                                    + " asientos_disponibles = " + asientosSobrantes + " WHERE "
                                    + "id_vuelo = '" + comboVuelosDisponibles.getSelectedItem().toString() + "';");
                            for (int i = 0; i < miBoleto.length; i++) {
                                int idBoleto = 0;
                                int idAsiento = 0;

                                //Seleccionando el asiento
                                getMiConexion().sendSQL("INSERT INTO asientos VALUES(null," + miBoleto[i].getAsiento() + ",'" + miBoleto[i].getIdVuelo() + "');");

                                //Obteniendo el id generado de ese asiento
                                getMiConexion().sendSQLQuery("SELECT id_asiento FROM asientos WHERE idvuelo = '" + miBoleto[i].getIdVuelo() + "' && numero_asiento=" + miBoleto[i].getAsiento() + ";");

                                //Cachando el asiento obtenido de la consulta
                                if (getMiConexion().getResultado().next())
                                idAsiento = getMiConexion().getResultado().getInt("id_asiento");
                                
                                getMiConexion().sendSQL("INSERT INTO boleto VALUES"
                                        + "( null,'" + miBoleto[i].getIdPasajero() + "','" + miBoleto[i].getIdVuelo() + "',"
                                        + idAsiento + ");");

                                getMiConexion().sendSQLQuery("SELECT id_boleto FROM boleto "
                                        + "WHERE id_cliente ='" + miBoleto[i].getIdPasajero()
                                        + "' && id_vuelo='" + miBoleto[i].getIdVuelo() + "' && id_asiento=" + idAsiento);
                                if (getMiConexion().getResultado().next()) {
                                    idBoleto = getMiConexion().getResultado().getInt("id_boleto");
                                }

                                System.out.println(selectorDeFecha.getEditor().getText());
                                getMiConexion().sendSQL("INSERT INTO venta VALUES( null, '"
                                        + getidUsuario() + "'," + idBoleto + ","
                                        + Float.parseFloat(campoPrecioVuelo.getText())
                                        + ",'" + selectorDeFecha.getEditor().getText() + "','"
                                        + getHora() + "');");
                            }

                            getMiConexion().getConexion().commit();
                            getMiConexion().getConexion().setAutoCommit(true);


                            //---------------
                            /*PrinterJob job = PrinterJob.getPrinterJob();
                            Book book = new Book();
                            for (int i = 0; i < imprimirBoletos.length; i++) {
                                PreviewBoleto.getViewport().add(imprimirBoletos[i]);
                                PreviewBoleto.setViewportView(imprimirBoletos[i]);
                                book.append(imprimirBoletos[i], new PageFormat());
                            }
                            job.setPageable(book);
                            try {
                                if (job.printDialog()) {
                                    job.print();
                                }
                            } catch (HeadlessException headlessException) {
                            } catch (PrinterException printerException) {
                            }*/
                            //---------------

                            int n = JOptionPane.showConfirmDialog(
                                this, "La venta se ha hecho de forma exitosa\n" +
                                "desea imprimir los boletos generados?",
                                "Venta Exitosa",
                                JOptionPane.YES_NO_OPTION);
                            if (n==0){
                                for (int i = 0; i < imprimirBoletos.length; i++) {
                                    try {
                                        this.repaint();
                                        PrinterJob job = PrinterJob.getPrinterJob();
                                        job.setPrintable(imprimirBoletos[i]);
                                        PreviewBoleto.setViewportView(imprimirBoletos[i]);
                                        if (job.printDialog())
                                        job.print();
                                    } catch (PrinterException printerException) {
                                    }
                                }
                            }
                            reiniciarDatos();
                        }
                        else JOptionPane.showMessageDialog(this,
                            "Desafortunadamente ya no quedan boletos suficientes para satisfacer la venta.",
                            "No existen suficientes boletos",
                            JOptionPane.ERROR_MESSAGE);
                    } catch (SQLException ex) {
                        Logger.getLogger(PanelAtenderPasajeros.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
        else JOptionPane.showMessageDialog(this,
                 "Debe seleccionar un cliente primero.",
                 "No hay cliente seleccionado",
                 JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_jButton4MouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane PreviewBoleto;
    private javax.swing.JButton buttonBuscarUsuario;
    private javax.swing.JTextField campoAsientosLibres;
    private javax.swing.JTextField campoDestino;
    private javax.swing.JTextField campoIdCliente;
    private javax.swing.JTextField campoNombreCompletoCliente;
    private javax.swing.JTextField campoOrigen;
    private javax.swing.JTextField campoPagoTotal;
    private javax.swing.JTextField campoPrecioVuelo;
    private javax.swing.JTextField campoRfcCliente;
    private javax.swing.JComboBox comboVuelosDisponibles;
    private javax.swing.JTextField fieldBuscarUsuario;
    private javax.swing.JList horasSalida;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSpinner selectorBoletos;
    private org.jdesktop.swingx.JXDatePicker selectorDeFecha;
    // End of variables declaration//GEN-END:variables

}
